#!/usr/bin/env python
# -*- coding: UTF-8 -*-
'''
@Project ：zhcx-service-test
@File    ：test001.py
@Author  ：关依林
@Date    ：2023/11/22 19:19
'''
import collections
from typing import List, Set

def contains(department: str, listing_dept: list[str]) -> bool:
    if not listing_dept:
        return False
    if department in listing_dept:
        return True
    return parent_contains(department, listing_dept)


def parent_contains(department: str, listing_dept: list[str]) -> bool:
    parent_path = get_parent_path(department)
    if not parent_path:
        return False
    if parent_path in listing_dept:
        return True
    return parent_contains(parent_path, listing_dept)


def get_parent_path(department: str) -> str:
    left_br = department.rfind("{")
    if left_br <= 0:
        return None
    return department[:left_br - 1]

if __name__ == '__main__':
    print(contains(department="{0}_{3}_{517}_{60}", listing_dept=["{0}_{3}_{517}"]))